package com.tengju.user.infrastructure.repository.convert;

import com.tengju.user.domain.model.archive.IdCardNo;
import com.tengju.user.domain.model.archive.resume.BankCard;
import com.tengju.user.domain.model.archive.resume.BankCardId;
import com.tengju.user.domain.model.archive.resume.BankCardStatus;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.shared.AccountId;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.BankCardDO;

public class BankCardConvert {

    public static BankCard convert(BankCardDO bankCardDO) {
        if (bankCardDO == null) {
            return null;
        }
        return new BankCard(new BankCardId(bankCardDO.getId()),
                new AccountId(bankCardDO.getAccountId()),
                new UserIdCode(bankCardDO.getIdCode()),
                new IdCardNo(bankCardDO.getIdcardNo()),
                bankCardDO.getIdcardName(),
                bankCardDO.getBankNo(),
                bankCardDO.getBankName(),
                BankCardStatus.form(bankCardDO.getStatus()));
    }

    public static BankCardDO convert(BankCard bankCard) {
        if (bankCard == null) {
            return null;
        }
        BankCardDO bankCardDO = new BankCardDO();
        bankCardDO.setIdCode(bankCard.getIdCode().getValue());
        bankCardDO.setAccountId(bankCard.getAccountId().getValue());
        bankCardDO.setIdcardNo(bankCard.getIdCardNo().getValue());
        bankCardDO.setIdcardName(bankCard.getIdCardName());
        bankCardDO.setBankNo(bankCard.getBankNo());
        bankCardDO.setBankName(bankCard.getBankName());
        bankCardDO.setStatus(bankCard.getStatus().getVal());
        return bankCardDO;
    }

    public static BankCardDO convert(BankCardId bankCardId, BankCard bankCard) {
        if (bankCardId == null || bankCard == null) {
            return null;
        }
        BankCardDO bankCardDO = convert(bankCard);
        bankCardDO.setId(bankCardId.getValue());
        return bankCardDO;
    }
}
